package com.mjlf.mqserver.server;

import com.alibaba.fastjson.JSONObject;
import com.mjlf.mqserver.entity.Topic;
import com.mjlf.mqserver.inter.TopicFactory;
import com.mjlf.restclient.entity.RestParams;
import com.mjlf.restclient.template.RestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @ClassName TopicServer
 * @Author mjlft
 * @Date 2020/2/18 16:12
 * @Version 1.0
 * @Description TODO
 */
@Service
public class TopicMqServer implements TopicFactory {
    @Value("${server.topic.path}")
    private String url;

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public String createTopic(Topic topic) throws Exception {
        RestParams restParams = new RestParams();
        restParams.setUrl(url);
        restParams.setParams(JSONObject.toJSONString(topic));
        return restTemplate.post(restParams);
    }

    @Override
    public String deleteTopic(String topicName) {
        return null;
    }
}
